package com.gd.iot.energy.controller.systemadmin;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.systemadmin.dto.EquipConcentSaveDTO;
import com.gd.iot.energy.pojo.systemadmin.dto.SupplierSaveDTO;
import com.gd.iot.energy.pojo.systemadmin.vo.EnumVO;
import com.gd.iot.energy.pojo.systemadmin.vo.EquipConcentPageVO;
import com.gd.iot.energy.pojo.systemadmin.vo.EquipConcentVO;
import com.gd.iot.energy.pojo.systemadmin.vo.HouseholdVO;
import com.gd.iot.energy.service.systemadmin.EquipConcentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 系统管理-档案管理-集中器管理
 *
 * @Description:
 * @Author: zgyz
 * @Date: 2020/8/28 23:20
 */
@Api(value = "系统管理-档案管理-集中器管理",tags = "系统管理-档案管理-集中器管理")
@RestController
@RequestMapping("/admin/concent")
public class ConcentController {

    @Autowired
    private EquipConcentService equipConcentService;

    @ApiOperation("获取集中器分页列表")
    @SystemLogRecordMonitor("获取集中器分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "conncentSerialnumber", value = "集中器编号", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "conncentName", value = "集中器名称", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "areaId", value = "区域ID", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型(asc,desc)", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getPageList")
    public ResponseEntity<PageVO<EquipConcentPageVO>> getPageList(
            @RequestParam(value = "conncentSerialnumber",required = false)String conncentSerialnumber,
            @RequestParam(value = "conncentName",required = false)String conncentName,
            @RequestParam(value = "areaId",required = false)Integer areaId,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<EquipConcentPageVO> pageVO = equipConcentService.getPageList(conncentSerialnumber,conncentName,areaId,
                pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @ApiOperation("获取集中器列表")
    @SystemLogRecordMonitor("获取集中器列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "areaOrg", value = "区域编号", dataType = "string", paramType = "query", example = "", required = true),
            @ApiImplicitParam(name = "conncentName", value = "集中器名称", dataType = "string", paramType = "query", example = "", required = false)
    })
    @PostMapping("/getList")
    public ResponseEntity<List<EquipConcentVO>> getList(@RequestParam(value = "areaOrg",required = true,defaultValue = "10")Integer areaOrg,
                                                        @RequestParam(value = "conncentName",required = false)String conncentName) {

        List<EquipConcentVO> equipConcentVOs = equipConcentService.getEquipConcentVOs(areaOrg, conncentName);
        return new ResponseEntity<>(equipConcentVOs);
    }

    @ApiOperation("获取集中器")
    @SystemLogRecordMonitor("获取集中器")
    @PostMapping("/get")
    public ResponseEntity<EquipConcentSaveDTO> get(Integer id){
        EquipConcentSaveDTO equipConcentSaveDTO = equipConcentService.get(id);
        return new ResponseEntity<>(equipConcentSaveDTO);
    }

    @ApiOperation("新增集中器")
    @SystemLogRecordMonitor("新增集中器")
    @PostMapping("/add")
    public ResponseEntity<Long> add(@RequestBody EquipConcentSaveDTO equipConcentSaveDTO){
        Long id = equipConcentService.add(equipConcentSaveDTO);
        return new ResponseEntity<>(id);
    }

    @ApiOperation("更新集中器")
    @SystemLogRecordMonitor("更新集中器")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody EquipConcentSaveDTO equipConcentSaveDTO){
        boolean res = equipConcentService.updateConcent(equipConcentSaveDTO);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("删除集中器")
    @SystemLogRecordMonitor("删除集中器")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody List<Integer> ids){
        boolean res = equipConcentService.delete(ids);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("获取相关枚举")
    @SystemLogRecordMonitor("获取相关枚举")
    @PostMapping("/getEquipmentType")
    public ResponseEntity<Map<String, List<EnumVO>>> getEquipmentType(){
        Map<String, List<EnumVO>> enums = equipConcentService.getEnums();
        return new ResponseEntity<>(enums);
    }
}
